<template>
    <div>
        <pt-table :data="data" url="channel-models" ref="tableRef"></pt-table>
        <pt-form type="dialog" url="channel-models" :rules="formRule" ref="formRef"></pt-form>
    </div>
</template>

<script setup lang="ts">
import { onMounted, ref } from 'vue'
import { routeNamePush } from '@/utils'

const formRef = ref()
const tableRef = ref()

onMounted(() => {
    tableRef.value.action.setFormRef(formRef)
    tableRef.value.action.on('tools', async (arg: any) => {
        await routeNamePush('model.design', { id: arg['id'] })
    })
})

const data = {
    header: {
        buttons: ['add', 'refresh', 'extend'],
        searchExtend: false,
    },
    column: [
        { type: 'index', width: '60' },
        { prop: 'title', label: '模型标题' },
        { prop: 'table_name', label: '数据表名称' },
        { prop: 'is_release', label: '会员投稿', render: 'tag' },
        { prop: 'is_one_page', label: '单页模型', render: 'tag' },
        { prop: 'weight', label: '权重' },
        { prop: 'status', label: '是否启用', render: 'switches' },
        {
            prop: 'operate',
            label: '操作',
            width: '150',
            fixed: 'right',
            buttons: [{ icon: 'tools', event: 'tools' }, 'edit', 'del'],
        },
    ],
}

const options = [
    { label: '否', value: 0 },
    { label: '是', value: 1 },
]

const formRule = {
    title: '模型管理',
    props: { labelPosition: 'right', labelWidth: '120px' },
    rules: [
        { field: 'title', label: '模型标题', required: true },
        { field: 'table_name', label: '绑定数据表', required: true },
        { type: 'number', field: 'weight', value: 99, label: '权重' },
        { type: 'radio', field: 'is_one_page', label: '是否单页模型', value: 0, options },
        { type: 'radio', field: 'is_release', label: '是否允许投稿', value: 0, options },
        { type: 'radio', field: 'is_archive', label: '是否归档', value: 1, options },
        { type: 'textarea', field: 'intro', label: '表单备注' },
    ],
}
</script>

<style scoped></style>
